package com.wwy.arithmetic.suanfa;

import lombok.Data;
import sun.reflect.generics.tree.Tree;

import java.util.List;

public class ZxblTest {

    @Data
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }

        public TreeNode() {
        }
        public TreeNode(TreeNode left,TreeNode right){
            this.left = left;
            this.right = right;
        }
    }

    public static void main(String[] args) {
        TreeNode treeNode =  new TreeNode();
        treeNode.setVal(3);
        TreeNode treeNode1 =  new TreeNode();
        treeNode1.setVal(9);
        TreeNode treeNode2 =  new TreeNode();
        treeNode2.setVal(20);
        TreeNode treeNode3 =  new TreeNode();
        treeNode3.setVal(15);
        TreeNode treeNode4 =  new TreeNode();
        treeNode4.setVal(7);
        treeNode.setLeft(treeNode1);
        treeNode.setRight(treeNode2);
        treeNode2.setLeft(treeNode3);
        treeNode2.setRight(treeNode4);
    }
//    public  static Integer  zdsd(TreeNode treeNode,int num){
//
//    }
    public int maxDepth(TreeNode root) {
//终止条件：当树为空时结束递归，并返回当前深度0
        if(root == null){
            return 0;
        }
        //root的左、右子树的最大深度
        int leftDepth = maxDepth(root.left);
        int rightDepth = maxDepth(root.right);
        //返回的是左右子树的最大深度+1
        return Math.max(leftDepth, rightDepth) + 1;
    }
}
